package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.GoodStyle;
import cn.wolfcode.trip.base.domain.Goods;
import cn.wolfcode.trip.base.mapper.GoodsMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IGoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    public PageInfo<Goods> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Goods> list = goodsMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    public void saveOrUpdate(Goods entity) {
        if (entity.getId() == null) {
            goodsMapper.insert(entity);
        } else {
            goodsMapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    public Goods get(Long goodsId) {
        return goodsMapper.selectByPrimaryKey(goodsId);
    }

}
